package com.blog.service.impl;

import com.blog.utils.SecurityUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("ps")
public class PermissionServiceImpl {

	/**判断当前用户是否有此权限
	 *
	 * @param permission 要判断权限
	 * @return
	 */
	public boolean hasPermission(String permission){
		//超级管理员 直接返回true
		if(SecurityUtils.isAdmin()){
			return true;
		}


		//否则，获取当前用户的权限列表，判断是否具有某个权限
		List<String> permissions = SecurityUtils.getLoginUser().getPermissions();
		return permissions.contains(permission);
	}
}
